import {reactRouter} from "@react-router/dev/vite";
import autoprefixer from "autoprefixer";
import tailwindcss from "tailwindcss";
import {defineConfig} from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import {glob} from 'glob';

export default defineConfig({
  server: {
    port: 5173,
    proxy: {
      "/api": {
        target: "http://192.168.5.100:3333",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
  css: {
    postcss: {
      plugins: [tailwindcss, autoprefixer],
    },
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@adobe/react-spectrum/dist/vars/spectrum-global.css";`,
      },
    },
  },
  plugins: [reactRouter(), tsconfigPaths(),],

  ssr: {
    noExternal: [
      '@adobe/react-spectrum',
      '@react-spectrum/*',
      '@spectrum-icons/*'
    ].flatMap((spec) => glob.sync(`${spec}`, { cwd: 'node_modules/' }))
  }

});